package com.jaux.hotel.common;

import lombok.Data;

/**
 * @author JAUX
 */
@Data
public class Result<T> {

    /**
     * 编码：
     * 200：请求成功
     * 40X：前端出错，404(网页资源未找到)
     * 50X：后端出错，505(请求资源出现问题)
     */
    private Integer code;
    /** 错误信息 */
    private String msg;
    /** 数据 */
    private T data;

    //private Map map = new HashMap(); //动态数据

    public static <T> Result<T> success(T object, String msg) {
        Result<T> r = new Result<T>();
        r.data = object;
        r.code = 200;
        r.msg = msg;
        return r;
    }
    public static <T> Result<T> success(String msg) {
        Result<T> r = new Result<T>();
        r.data = null;
        r.code = 200;
        r.msg = msg;
        return r;
    }
    public static <T> Result<T> error(String msg, Integer code) {
        Result r = new Result();
        r.msg = msg;
        r.code = code;
        return r;
    }
    public static <T> Result<T> error(String msg) {
        Result r = new Result();
        r.msg = msg;
        r.code = 500;
        return r;
    }

    //public R<T> add(String key, Object value) {
    //    this.map.put(key, value);
    //    return this;
    //}


}
